<template>
	<view>
		<uni-search-bar style="background-color: #fff;" placeholder="请输入客户联系人名称进行查询" @confirm="getDataList"
			v-model="queryParam.Keyword" @cancel="cancel">
		</uni-search-bar>
		<uni-list>
			<uni-list-item v-for="item in data" :key="item.Id" :title="item.cName" :note="item.cPhone" showArrow
				clickable @click="toForm(item)" />
		</uni-list>
		<!-- 上拉显示更多 -->
		<view class="" style="padding-bottom: 60rpx;">
			<uniLoadMore :status="status" :contentText="contentText" :rows="data"></uniLoadMore>
		</view>
	</view>
</template>

<script>
	// 引入加载更多
	import uniLoadMore from '@/components/uni-load-more.vue'
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				// 加载状态
				status: "loading",
				contentText: {
					contentdown: '',
					contentrefresh: '加载中',
					contentnomore: '没有更多了'
				},
				data: [],
				pagination: {
					PageIndex: 1,
					PageRows: 30,
					SortField: "CreateTime",
					SortType: "desc",
				},
				total: 0,
				queryParam: {
					Keyword: "",
					keys: "",
				},
				// 从订单详情传递过来的
				selectType: ""
			}
		},
		onNavigationBarButtonTap(e) {
			console.log(e);
			uni.navigateTo({
				url: '/pages/Information/page/ContactPerson/ContactPersonForm'
			})
		},
		onLoad(options) {
			this.queryParam.SupplieId = uni.getStorageSync('CompanyInfo').Id
		},
		onShow() {
			this.pagination.PageIndex = 1
			this.getDataList()
		},
		onReachBottom() {
			if (this.data.length >= this.total) return
			this.pagination.PageIndex++
			uni.showLoading()
			this.$http('post', '/BO/CustomerLinkman/GetDataList', {
					...this.pagination,
					Search: this.queryParam
				})
				.then(res => {
					uni.hideLoading()
					if (res.Success) {
						this.data = this.data.concat(res.Data)
						this.total = res.Total
					} else uni.showToast({
						icon: 'none',
						title: res.Msg
					})
				})
		},
		methods: {
			getDataList() {
				if (!this.queryParam.keys) return this.status = 'noMore'
				this.status = "loading"
				this.$http('post', '/BO/CustomerLinkman/GetDataList', {
						...this.pagination,
						Search: this.queryParam
					})
					.then(res => {
						uni.hideLoading()
						if (res.Success) {
							this.data = res.Data
							this.total = res.Total
							this.status = "noMore"
						} else uni.showToast({
							icon: 'none',
							title: res.Msg
						})
						this.status = "noMore"
						console.log(this.total);
					})
			},
			toForm(item) {
				uni.navigateTo({
					url: '/pages/Information/page/ContactPerson/ContactPersonForm?Id=' + item.Id
				})

			},
			cancel() {
				this.queryParam.Keyword = ''
				this.getDataList()
			}
		}
	}
</script>

<style>

</style>